<?php
require_once '../../include/common.inc.php';
require_once '../function.php';
if(stripos(auth_group($_SESSION['login_gid']),'users_group')===false)exit("没有权限！");
switch($act){
	case "lecturer_add":
		lecturer_add($name,$remark,$ord,$videonum,$roomview,$roomid,$is_show,$ico);
	break;
	case "lecturer_del":
        lecturer_del($id);
	break;
	case "group_edit":
        lecturer_edit($id,$name,$remark,$ord,$videonum,$roomview,$roomid,$is_show,$ico);
	break;
}
?>
<!DOCTYPE HTML>
<html>
   <head>
   <title></title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <link href="../assets/css/dpl-min.css" rel="stylesheet" type="text/css" />
   <link href="../assets/css/bui-min.css" rel="stylesheet" type="text/css" />
   <link href="../assets/css/page-min.css" rel="stylesheet" type="text/css" />
   <!-- 下面的样式，仅是为了显示代码，而不应该在项目中使用-->
   <link href="../assets/css/prettify.css" rel="stylesheet" type="text/css" />
   <style type="text/css">
code { padding: 0px 4px; color: #d14; background-color: #f7f7f9; border: 1px solid #e1e1e8; }
</style>
   </head>
   <body>
<div class="container" style=" min-width:700px;">
     <ul class="breadcrumb">
    <li class="active">
         <button type="submit"  class="button button-success" id="add_group_bt"><i class="icon icon-plus icon-white"></i> 添加</button>
         &nbsp;&nbsp;</li>
  </ul>
     <table  class="table table-bordered table-hover definewidth m10" >
    <thead>
         <tr style="font-weight:bold" >
        <td width="50" align="center" bgcolor="#FFFFFF">编号</td>
        <td width="150" align="center" bgcolor="#FFFFFF">讲师名称</td>
        <td align="150" bgcolor="#FFFFFF">讲师描述</td>
        <td width="60" align="center" bgcolor="#FFFFFF">列表排序</td>
         <td align="60" bgcolor="#FFFFFF">视频数量</td>
         <td align="60" bgcolor="#FFFFFF">观看人数</td>
         <td align="60" bgcolor="#FFFFFF">房间id</td>
         <td width="120" align="center" bgcolor="#FFFFFF">头像</td>
         <td width="120" align="center" bgcolor="#FFFFFF">是否显示</td>
        <td width="230" align="center" bgcolor="#FFFFFF">操作</td>
      </tr>
       </thead>
    <form method="post" enctype="application/x-www-form-urlencoded">
         <tr id="act_group" style="display:none">
        <td align="center" valign="middle" bgcolor="#FFFFFF"><span class="label label-info" id="actstate">Info</span></td>

        <td align="center" valign="middle" bgcolor="#FFFFFF">   <input name="name" type="text" id="name"/></td>

        <td align="center" valign="middle" bgcolor="#FFFFFF">
            <input name="remark" type="text" id="remark" style="width:400px;"/>
<!--            <textarea name="remark" id="remark" cols="30" rows="10">-->
<!--            </textarea>-->

        </td>
        <td align="center" valign="middle" bgcolor="#FFFFFF"><input name="ord" type="text" id="ord" style="width:40px;"/></td>
        <td align="center" valign="middle" bgcolor="#FFFFFF"><input name="videonum" type="text" id="videonum" style="width:40px;"/></td>
        <td align="center" valign="middle" bgcolor="#FFFFFF"><input name="roomview" type="text" id="roomview" style="width:40px;"/></td>
        <td align="center" valign="middle" bgcolor="#FFFFFF"><input name="roomid" type="text" id="roomid" style="width:40px;"/></td>

             <td align="center" valign="middle" bgcolor="#FFFFFF"><button class="button button-mini button-danger"  id="group_up_bnt">上传</button>
             <input type="hidden" id="ico" name="ico">
             <input type="hidden" id="act" name="act">
             <input type="hidden" id="id" name="id">
             <img src="" style="border:0px; height:20px; float:left" id="ico_src"/></td>
             <td align="center" valign="middle" bgcolor="#FFFFFF"><input name="is_show" type="text" id="is_show" style="width:40px;"/></td>

             <td align="center" valign="middle" bgcolor="#FFFFFF"><button class="button   button-success" id="act_group_sub" type="submit"><i class="x-icon icon-ok icon-white"></i> 确定</button></td>

         </tr>
       </form>
<?php
$query=$db->query("select * from {$tablepre}lecturer order by id desc");
while($row=$db->fetch_row($query)){
    $row[remark]=str_replace("n",'',str_replace(chr(13),'',$row[remark]));
?>

    <tr style="display: none">
        <td id="copyremark"><?=$row[remark]?></td>
    </tr>
    <tr>
         <td bgcolor="#FFFFFF" align="center"><?=$row[id]?></td>
         <td bgcolor="#FFFFFF" align="center"><?=$row[name]?>&nbsp; </td>
<!--         <td align="center" bgcolor="#FFFFFF">-->
<!--             <textarea name="" id="" cols="30" rows="10">--><?//=$row[remark]?><!--</textarea>-->
<!---->
<!--        </td>-->

        <td bgcolor="#FFFFFF" align="center"><?=$row[remark]?>&nbsp; </td>
        <td align="center" bgcolor="#FFFFFF"><?=$row[ord]?>&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF"><?=$row[videonum]?>&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF"><?=$row[roomview]?>&nbsp;</td>
        <td align="center" bgcolor="#FFFFFF"><?=$row[roomid]?>&nbsp;</td>
        <td bgcolor="#FFFFFF" align="center"><img src="<?=$row[ico]?>" style="border:0px; height:20px; float:left" id="ico_src"/></td>
        <td align="center" bgcolor="#FFFFFF"><?=$row[is_show]?>&nbsp;</td>
         <td bgcolor="#FFFFFF" align="center">
        <button class="button button-mini button-info"  onClick="lecturer_edit_btn('<?=$row[id]?>','<?=$row[name]?>','<?=$row[remark]?>','<?=$row[ord]?>','<?=$row[videonum]?>','<?=$row[roomview]?>','<?=$row[roomid]?>','<?=$row[is_show]?>','<?=$row[ico]?>')"><i class="x-icon x-icon-small icon-wrench icon-white"></i>修改</button>
        <button class="button button-mini button-danger" onclick="if(confirm('是否确认删除？'))location.href='?act=lecturer_del&id=<?=$row[id]?>'" ><i class="x-icon x-icon-small icon-trash icon-white"></i>删除</button></td>
    </tr>
<?php }?>       
  </table>
     <div class="row">
    
  </div>
   </div>
<script type="text/javascript" src="../assets/js/jquery-1.8.1.min.js"></script> 
<script type="text/javascript" src="../assets/js/bui.js"></script> 
<script type="text/javascript" src="../assets/js/config.js"></script> 
<script type="text/javascript" src="../../upload/swfupload/swfupload.js"></script> 
<script>
BUI.use('bui/overlay',function(Overlay){
            dialog = new Overlay.Dialog({
            title:'用户组权限编辑',
            width:800,
            height:600,
            buttons:[],
            bodyContent:''
          });
});
function openRule(id,type){
	dialog.set('bodyContent','<iframe src="group_rule.php?id='+id+'&type='+type+'" scrolling="yes" frameborder="0" height="100%" width="100%"></iframe>');
	dialog.updateContent();
	dialog.show();
}
function openGroupUser(id,name){
	top.topManager.openPage({
		id : 'GroupUser'+id,
		href : 'users/users.php?gid='+id,
		title : name+' 成员'
	  });
	top.topManager.reloadPage();
}

  function lecturer_edit_btn(id,name,remark,ord,videonum,roomview,roomid,is_show,ico){

  		$("#act").val("group_edit");
		$("#act_group").show();
		$("#id").val(id);
		$("#name").val(name);
//		$("#remark").val($('#copyremark').html());
		$("#remark").val(remark);

		$("#ord").val(ord);
		$("#videonum").val(videonum);
		$("#roomview").val(roomview);
		$("#roomid").val(roomid);
		$("#is_show").val(is_show);
		$("#ico").val(ico);
		$("#ico_src").attr("src",ico);
		$("#actstate").html("修改");
  }

  function swfupload_ok(fileObj,server_data){
	 var data=eval("("+server_data+")") ;
	 $('#ico').val(data.msg.url);
	 $('#ico_src').attr("src",data.msg.url);
	 //alert(data.msg.url);
  }
  $(function(){


  var swfdef={
	  // 按钮设置
	    file_post_name:"filedata",
		button_width: 35,
		button_height: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_text: '<span class="upbnt">上传</span>',
		button_text_style: ".upbnt{ color:#00F}",
		button_text_left_padding: 0,
		button_text_top_padding: 0,
		upload_success_handler : swfupload_ok,
		file_dialog_complete_handler:function(){this.startUpload();},
		file_queue_error_handler:function(){alert("选择文件错误");}
		}
  swfdef.flash_url="../../upload/swfupload/swfupload.swf";
  swfdef.button_placeholder_id="group_up_bnt";
  swfdef.file_types="*.gif;*.jpg;*.png";
  swfdef.upload_url="../../upload/upload.php";
  
  swfu = new SWFUpload(swfdef);
  $("#add_group_bt").on("click",function(){
		$("#act_group").toggle();
		$("#act").val("lecturer_add");

          $("#name").val('');
          $("#remark").val('');
          $("#ord").val('');
          $("#videonum").val('');
          $("#roomview").val('');
          $("#roomid").val('');
          $("#is_show").val('');
          $("#ico").val('');
          $("#ico_src").attr("src",'');

		$("#actstate").html("添加");
  });
});

  </script>

<script>
    //换行转回车
//    var haha=document.getElementById("remark").value;
//    haha=haha.replace('<br />','/n');
//    document.getElementById("SendTextArea").value=haha;

//    HTMLTextAreaElement.prototype.getCaretPosition = function () {
////return the caret position of the textarea
//        return this.selectionStart;
//    };
//    HTMLTextAreaElement.prototype.setCaretPosition = function (position) {
////change the caret position of the textarea
//        this.selectionStart = position;
//        this.selectionEnd = position;
//        this.focus();
//    };
//    HTMLTextAreaElement.prototype.hasSelection = function () {
////if the textarea has selection then return true
//        if (this.selectionStart == this.selectionEnd) {
//            return false;
//        } else {
//            return true;
//        }
//    };
//    HTMLTextAreaElement.prototype.getSelectedText = function () {
////return the selection text
//        return this.value.substring(this.selectionStart, this.selectionEnd);
//    };
//    HTMLTextAreaElement.prototype.setSelection = function (start, end) {
////change the selection area of the textarea
//        this.selectionStart = start;
//        this.selectionEnd = end;
//        this.focus();
//    };
//    var textarea = document.getElementsByTagName('textarea')[0];
//    textarea.onkeydown = function(event) {
//        //support tab on textarea
//        if (event.keyCode == 9) { //tab was pressed
//            var newCaretPosition;
//            newCaretPosition = textarea.getCaretPosition() + " ".length;
//            textarea.value = textarea.value.substring(0, textarea.getCaretPosition()) + " " + textarea.value.substring(textarea.getCaretPosition(), textarea.value.length);
//            textarea.setCaretPosition(newCaretPosition);
//            return false;
//        }
//        if(event.keyCode == 8){
//            //backspace
//            if (textarea.value.substring(textarea.getCaretPosition() - 4, textarea.getCaretPosition()) == " ") {
//                //it's a tab space
//                var newCaretPosition;
//                newCaretPosition = textarea.getCaretPosition() - 3;
//                textarea.value = textarea.value.substring(0, textarea.getCaretPosition() - 3) + textarea.value.substring(textarea.getCaretPosition(), textarea.value.length);
//                textarea.setCaretPosition(newCaretPosition);
//            }
//        }
//        if(event.keyCode == 37){ //left arrow
//            var newCaretPosition;
//            if (textarea.value.substring(textarea.getCaretPosition() - 4, textarea.getCaretPosition()) == " ") {
//                //it's a tab space
//                newCaretPosition = textarea.getCaretPosition() - 3;
//                textarea.setCaretPosition(newCaretPosition);
//            }
//        }
//        if(event.keyCode == 39){
//            //right arrow
//            var newCaretPosition;
//            if (textarea.value.substring(textarea.getCaretPosition() + 4, textarea.getCaretPosition()) == " ") {
//                //it's a tab space
//                newCaretPosition = textarea.getCaretPosition() + 3;
//                textarea.setCaretPosition(newCaretPosition);
//            }
//        }
//    }


</script>
</body>
</html>
